package WinterHomework.day13;

//LeetCode 917号，仅仅反转字母
public class Demo02 {
    public String reverseOnlyLetters(String s) {
        int start = 0, end = s.length() - 1;
        char[] ch = s.toCharArray();
        while (start < end) {
            //判断是否是字母Character.isAlphabetic();
            while (start < end && !Character.isAlphabetic(s.charAt(start))) {
                start++;
            }
            while (start < end && !Character.isAlphabetic(s.charAt(end))) {
                end--;
            }
            swap(ch, start, end);
            start++;
            end--;
        }
        return new String(ch);
    }

    private void swap(char[] ch, int start, int end) {
        char temp = ch[start];
        ch[start] = ch[end];
        ch[end] = temp;
    }
}
